package com.hmyd.hmyd_android.utils;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.dto.ServiceQQ;
import com.hmyd.hmyd_android.utils.Utils;

public class ExclusiveServicePop extends PopupWindow {
	private ImageView mImageView;
	private Button mButton;
	private TextView mTvName;
	private TextView mTvIntrduce;
	private onGetQQListener callback;

	public interface onGetQQListener {

		public Void onGet(String qq);
	}

	public ExclusiveServicePop(final Context context, final ServiceQQ QQ) {

		// mMoreEntity = wisdomMoreEntity;
		setContentView(LayoutInflater.from(context).inflate(R.layout.view_exclusive_service_pop,
				null));
		// 设置SelectPicPopupWindow弹出窗体的宽
		setWidth(LayoutParams.MATCH_PARENT);
		// 设置SelectPicPopupWindow弹出窗体的高
		setHeight(LayoutParams.MATCH_PARENT);
		setFocusable(true);
		setOutsideTouchable(true);
		// 设置SelectPicPopupWindow弹出窗体动画效果
		// setAnimationStyle(R.anim.left_in);
		// 实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(Color.argb(0, 0, 0, 0));
		// 设置SelectPicPopupWindow弹出窗体的背景
		setBackgroundDrawable(dw);

		callback = (onGetQQListener) context;
		mImageView = (ImageView) getContentView().findViewById(R.id.iv);
		mButton = (Button) getContentView().findViewById(R.id.select_service);
		mTvName = (TextView) getContentView().findViewById(R.id.tv_name);
		mTvIntrduce = (TextView) getContentView().findViewById(R.id.tv_introduction);

		mTvName.setText(QQ.name);
		mTvName.setText(QQ.message);

		LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) mImageView
				.getLayoutParams();
		params.width = Utils.screenWidth_ * 2 / 5;
		mImageView.setLayoutParams(params);
		getContentView()
				.setAnimation(AnimationUtils.loadAnimation(context, android.R.anim.fade_in));

		final String qq = QQ.qq;
		mButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (TextUtils.isEmpty(qq)) {
					callback.onGet("800038762");
				} else {
					callback.onGet(qq);
				}
				dismiss();
			}
		});

		getContentView().setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				dismiss();
				return false;
			}
		});
	}

}
